package cc.rengu.igas.momp.core.service.trans;

import cc.rengu.igas.momp.common.constant.CommonConstant;
import cc.rengu.igas.momp.common.dao.McMchntInfoMapper;
import cc.rengu.igas.momp.common.dao.McUserInfoMapper;
import cc.rengu.igas.momp.common.dao.MchntInfoMapper;
import cc.rengu.igas.momp.common.dao.PlatBizTmpMapper;
import cc.rengu.igas.momp.common.dao.impl.McMchntInfoMapperImpl;
import cc.rengu.igas.momp.common.dao.impl.McUserInfoMapperImpl;
import cc.rengu.igas.momp.common.dao.impl.MchntInfoMapperImpl;
import cc.rengu.igas.momp.common.dao.impl.PlatBizTmpMapperImpl;
import cc.rengu.igas.momp.common.entity.*;
import cc.rengu.igas.momp.common.enums.*;
import cc.rengu.igas.momp.common.model.bean.JsonTmpCpMcInfo;
import cc.rengu.igas.momp.common.model.bean.JsonTmpMcMchntInfo;
import cc.rengu.igas.momp.common.model.bean.JsonTmpMcUserInfo;
import cc.rengu.igas.momp.common.util.JsonOperation;
import cc.rengu.igas.momp.facade.bean.CouponMcInfoBean;
import cc.rengu.igas.momp.facade.bean.McMchntInfoBean;
import cc.rengu.igas.momp.facade.bean.McUserInfoBean;
import cc.rengu.igas.momp.facade.bean.MoneyOffMcListInfoBean;
import cc.rengu.igas.momp.facade.request.QueryMcMerUserListRequest;
import cc.rengu.igas.momp.facade.response.QueryMcMerUserListInfoResponse;
import cc.rengu.oltp.service.base.RadpService;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.enums.ChannelEnum;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.bean.PageInfo;
import cc.rengu.oltp.utility.bean.PageResult;
import cc.rengu.oltp.utility.util.ConvertUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.base.StringUtil;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 营销活动商户/用户列表查询功能实现
 *
 * @author liujinan
 * @date 2021/3/22 17:26
 */
public class QueryMcMerUserListService extends RadpService {


    /**
     * 法人机构号
     */
    private String globalInstId;
    /**
     * 操作类型
     */
    private String globalQueryType;
    /**
     * 操作人
     */
    private String globalQueryId;
    /**
     * 操作角色
     */
    private String globalQueryRole;
    /**
     * 操作人所属机构
     */
    private String globalQueryOrgId;
    /**
     * 当前系统日期
     */
    private String globalTimeStamp;
    /**
     * 营销活动编号
     */
    private String globalMcNo;
    /**
     * 营销活动商户编号
     */
    private String globalMchntNo;
    /**
     * 营销活动商户类型
     */
    private String globalMchntType;
    /**
     * 营销活动类型
     */
    private String mcType;
    /**
     * 交易类型
     */
    private String transType;
    /**
     * 交易类型 商户列表
     */
    private static final String TRANS_TYPE_MER = "M";
    /**
     * 交易类型 商圈列表
     */
    private static final String TRANS_TYPE_AREAT = "A";
    /**
     * 交易类型 用户列表
     */
    private static final String TRANS_TYPE_USER = "U";

    @Override
    protected int bizInit(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizProcess(String s, int i) {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        try {

            QueryMcMerUserListRequest queryMcMerUserListRequest = new QueryMcMerUserListRequest();
            ConvertUtil.convertOutput(queryMcMerUserListRequest);

            QueryMcMerUserListInfoResponse queryMcMerUserListInfoResponse = new QueryMcMerUserListInfoResponse();
            queryMcMerUserListInfoResponse.setHeader(queryMcMerUserListRequest.getHeader());
            BizResponse<QueryMcMerUserListInfoResponse> bizResponse = new BizResponse<>();
            bizResponse.setResult(queryMcMerUserListInfoResponse);

            /* 报文检查 */
            messageValidation(queryMcMerUserListRequest);

            rglog.info("机构<{}>在<{}>由<{}>开始查询营销活动商戶/用戶列表信息流程", globalInstId, globalTimeStamp, globalQueryId);

            // 服务调用
            BizResponse<QueryMcMerUserListInfoResponse> bizResponseNew = queryMcMerUserList(xmlTreeUtil, queryMcMerUserListRequest, queryMcMerUserListInfoResponse);

            ConvertUtil.convertInput(bizResponseNew.getResult());

        } catch (BizException e) {
            rglog.error(StringUtil.ExceptionToString(e));
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, e.getCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e1));
            }
        } catch (Exception e) {
            rglog.error(StringUtil.ExceptionToString(e));
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e1));
            }
        }

        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizTerminate(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    /**
     * 查询营销活动商戶、用戶列表信息
     *
     * @param xmlTreeUtil                    内部XML树
     * @param queryMcMerUserListRequest      营销活动商戶、用戶列表查询接口请求对象
     * @param queryMcMerUserListInfoResponse 营销活动商戶、用戶d列表查询接口应答对象
     * @return cc.rengu.oltp.service.model.BizResponse<cc.rengu.igas.momp.facade.response.QueryMcMerUserListInfoResponse> 营销活动商戶、用戶列表查询接口应答对象
     * @throws BizException 业务异常信息
     * @author Jinan Liu
     * @date 2020/5/27 22:41
     */
    private BizResponse<QueryMcMerUserListInfoResponse> queryMcMerUserList(XmlTreeUtil xmlTreeUtil, QueryMcMerUserListRequest queryMcMerUserListRequest, QueryMcMerUserListInfoResponse queryMcMerUserListInfoResponse)
            throws Exception {

        BizResponse<QueryMcMerUserListInfoResponse> bizResponse = new BizResponse<>();

        List<MoneyOffMcListInfoBean> moneyOffMcListInfoBeanList;
        //营销活动类型
        rglog.debug("当前是<{}>查询数据", QueryRoleEnum.getByValue(globalQueryRole).getQueryRoleDesc());
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPageIndex(Integer.parseInt(queryMcMerUserListRequest.getPageIndex()));
        pageInfo.setPageSize(Integer.parseInt(queryMcMerUserListRequest.getPageSize()));
        mcType = globalMcNo.substring(2, 4);

        /** 商户列表信息查询 */
        if (TRANS_TYPE_MER.equals(transType) || TRANS_TYPE_AREAT.equals(transType)) {
            //权限校验
            List<Object> mcMchntInfoList = new ArrayList<Object>();
            List<Object> mcUserInfoList;
            List<McMchntInfoBean> mcMchntInfoBeanList = new ArrayList<>();
            /** 减免类 */
            if (McTypeEnum.REDUCTION_FIXED_AMOUNT.getMcTypeCode().equals(mcType) || McTypeEnum.REDUCTION_RANDOM_AMOUNT.getMcTypeCode().equals(mcType) ||
                    McTypeEnum.REDUCTION_FIXED_RATE.getMcTypeCode().equals(mcType) || McTypeEnum.REDUCTION_RANDOM_RATE.getMcTypeCode().equals(mcType)) {

                switch (QueryTypeEnum.getByValue(globalQueryType)) {
                    case BANK_QUERY_TYPE:
                        /* 银行人员查询 */
                        mcMchntInfoList = getAllMcMchntListInfo(pageInfo);
                        if (null != mcMchntInfoList && !mcMchntInfoList.isEmpty()) {
                            mcMchntInfoBeanList = mcMchntInfoList.stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
                        }
                        queryMcMerUserListInfoResponse.setMchntInfoList(mcMchntInfoBeanList);
                        break;
                    case MCHNT_QYERY_TYPE:
                        /* 商户信息查询 */
                        mcMchntInfoList = getAllMcMchntListInfo(pageInfo);
                        if (null != mcMchntInfoList && !mcMchntInfoList.isEmpty()) {
                            mcMchntInfoBeanList = mcMchntInfoList.stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
                        }
                        queryMcMerUserListInfoResponse.setMchntInfoList(mcMchntInfoBeanList);
                        break;

                    default:
                        /* 其他查询角色不支持 */
                        rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                        throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                }

                /** 卡券类 */
            } else if (McTypeEnum.COUPON_ALL.getMcTypeCode().equals(mcType) || McTypeEnum.COUPON_FREE.getMcTypeCode().equals(mcType) ||
                    McTypeEnum.COUPON_PAID.getMcTypeCode().equals(mcType)) {

                /* 判断查询类型 */
                CpMcListInfoInObj cpMcListInfoInObj = new CpMcListInfoInObj();
                /* 机构编码 */
                cpMcListInfoInObj.setInstId(globalInstId);
                /* 营销活动编号 */
                cpMcListInfoInObj.setMcNo(globalMcNo);

                /* 根据角色权限查询数据 */
                switch (QueryTypeEnum.getByValue(globalQueryType)) {
                    case BANK_QUERY_TYPE:
                        /* 银行人员,需要拼接营销活动机构信息表查询 */

                        /* 机构编号 */
                        if (!StringUtil.isNullorEmpty(globalQueryOrgId)) {
                            cpMcListInfoInObj.setOrgId(globalQueryOrgId);
                        }

                        /* 银行人员查询营销活动详细信息 */
                        if (QueryRoleEnum.BANK_BASIC_QUERY_ROLE.getQueryRoleCode().equals(globalQueryRole) ||
                                QueryRoleEnum.BANK_PUBLISH_QYERY_ROLE.getQueryRoleCode().equals(globalQueryRole)) {
                            /* 查询营销活动商户信息 */
                            mcMchntInfoList = getAllMcMchntListInfo(pageInfo);
                            if (null != mcMchntInfoList && !mcMchntInfoList.isEmpty()) {
                                mcMchntInfoBeanList = mcMchntInfoList.stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
                            }
                            queryMcMerUserListInfoResponse.setMchntInfoList(mcMchntInfoBeanList);
                        } else if (QueryRoleEnum.BANK_AUDIT_QYERY_ROLE.getQueryRoleCode().equals(globalQueryRole)) {
                            /* 银行审批岗流程 */
                            TMPlatBizTmp tmPlatBizTmp = selectCouponMcDetailInfoByBankAuditRole(cpMcListInfoInObj);
                            if (null == tmPlatBizTmp) {
                                rglog.error("机构<{}>的卡券类营销活动<{}>的基本信息查询失败!用户无权限查看数据或不存在该营销活动", globalInstId, globalMcNo);
                                throw new BizException(RespCodeEnum.GET_MONEY_OFF_MC_DETAIL_ERROR.getRespCode(), RespCodeEnum.GET_MONEY_OFF_MC_DETAIL_ERROR.getRespDesc());
                            }
                            MoMcListInfoInObj moMcListInfoInObj = new MoMcListInfoInObj();
                            moMcListInfoInObj.setInstId(globalInstId);
                            moMcListInfoInObj.setMcNo(globalMcNo);

                            List<TMPlatBizTmp> tmPlatBizTmpList = getAllMcTmpInfo(moMcListInfoInObj);
                            /* 查询营销活动商户信息 */
                            List<TMPlatBizTmp> tmPlatBizTmpMchntList = tmPlatBizTmpList.stream().filter(record -> TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameCode().equals(record.getOprTableEname())).collect(Collectors.toList());
                            if (null != tmPlatBizTmpMchntList && !tmPlatBizTmpMchntList.isEmpty()) {
                                mcMchntInfoBeanList = tmPlatBizTmpMchntList.stream().map(this::convertTmpMcMchntInfo).collect(Collectors.toList());
                                /* 处理商户、商圈类型 */
                                rglog.info("机构<{}>的卡券类营销活动<{}>查询临时表商户列表size<{}>", globalInstId, globalMcNo, mcMchntInfoBeanList.size());
                                mcMchntInfoBeanList = mcMchntInfoBeanList.stream().filter(item -> globalMchntType.equals(item.getMchntType())).collect(Collectors.toList());
                                rglog.info("机构<{}>的卡券类营销活动<{}>商户列表筛选商户类型<{}>[0商户1商圈]，筛选后size<{}>", globalInstId, globalMcNo, globalMchntType, mcMchntInfoBeanList.size());
                            }
                            queryMcMerUserListInfoResponse.setMchntInfoList(mcMchntInfoBeanList);
                        } else {
                            rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                            throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                        }
                        break;
                    case MCHNT_QYERY_TYPE:
                        /* 商户人员 */
                        String mchntNo = globalQueryId;
                        TBMchntBaseInfo tbMchntBaseInfo = null;
                        if (!StringUtil.isNullorEmpty(mchntNo)) {
                            /* 校验商户信息 */
                            tbMchntBaseInfo = selectMompMchntBaseInfoByPrimaryKey(globalInstId, mchntNo);
                            if (null == tbMchntBaseInfo) {
                                rglog.error("查询法人机构<{}>商户<{}>基本信息失败!", globalInstId, mchntNo);
                                throw new BizException(RespCodeEnum.NO_TRANS_RECORD.getRespCode(), RespCodeEnum.NO_TRANS_RECORD.getRespDesc());
                            }
                        }
                        /* 查询营销活动商户列表信息 */
                        mcMchntInfoList = getAllMcMchntListInfo(pageInfo);
                        if (null != mcMchntInfoList && !mcMchntInfoList.isEmpty()) {
                            mcMchntInfoBeanList = mcMchntInfoList.stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
                        }
                        queryMcMerUserListInfoResponse.setMchntInfoList(mcMchntInfoBeanList);
                        break;
                    default:
                        /* 其他查询角色不支持 */
                        rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                        throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                }

                /** 手续费类 */
            } else if (McTypeEnum.MCHNT_FEE_DISCOUNT.getMcTypeCode().equals(mcType)) {

                if (QueryTypeEnum.BANK_QUERY_TYPE.getQueryTypeCode().equals(globalQueryType)) {
                    /* 银行人员查询 */
                    if (QueryRoleEnum.BANK_BASIC_QUERY_ROLE.getQueryRoleCode().equals(globalQueryRole) ||
                            QueryRoleEnum.BANK_PUBLISH_QYERY_ROLE.getQueryRoleCode().equals(globalQueryRole)) {
                        /* 查询营销活动商户信息 */
                        mcMchntInfoList = getAllMcMchntListInfo(pageInfo);
                        if (null != mcMchntInfoList && !mcMchntInfoList.isEmpty()) {
                            mcMchntInfoBeanList = mcMchntInfoList.stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
                        }
                        queryMcMerUserListInfoResponse.setMchntInfoList(mcMchntInfoBeanList);
                        /* 银行审批岗查询 */
                    } else if (QueryRoleEnum.BANK_AUDIT_QYERY_ROLE.getQueryRoleCode().equals(globalQueryRole)) {
                        /* 取临时表中所有数据 */
                        MoMcListInfoInObj moMcListInfoInObj = new MoMcListInfoInObj();
                        moMcListInfoInObj.setInstId(globalInstId);
                        moMcListInfoInObj.setMcNo(globalMcNo);

                        List<TMPlatBizTmp> tmPlatBizTmpList = getAllMcTmpInfo(moMcListInfoInObj);
                        if (null != tmPlatBizTmpList && !tmPlatBizTmpList.isEmpty()) {
                            List<TMPlatBizTmp> tmPlatBizTmpMchntList = tmPlatBizTmpList.stream().filter(record -> TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameCode().equals(record.getOprTableEname())).collect(Collectors.toList());
                            mcMchntInfoBeanList = tmPlatBizTmpMchntList.stream().map(this::convertTmpMcMchntInfo).collect(Collectors.toList());
                            /* 临时表区分商户、商圈数据 */
                            rglog.info("机构<{}>的卡券类营销活动<{}>查询临时表商户列表size<{}>", globalInstId, globalMcNo, mcMchntInfoBeanList.size());
                            mcMchntInfoBeanList = mcMchntInfoBeanList.stream().filter(item -> globalMchntType.equals(item.getMchntType())).collect(Collectors.toList());
                            rglog.info("机构<{}>的卡券类营销活动<{}>商户列表筛选商户类型<{}>[0商户1商圈]，筛选后size<{}>", globalInstId, globalMcNo, globalMchntType, mcMchntInfoBeanList.size());
                        }
                        queryMcMerUserListInfoResponse.setMchntInfoList(mcMchntInfoBeanList);
                    } else {
                        /* 其他查询角色不支持 */
                        rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                        throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                    }
                } else {
                    /* 其他查询角色不支持 */
                    rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                    throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                }
                /** 代理商 */
            } else if (McTypeEnum.AGENT_CASHBACK.getMcTypeCode().equals(mcType)) {
                rglog.error("营销活动类型上送错误!");
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                /** 收银员 */
            } else if (McTypeEnum.CASHER_CASHBACK.getMcTypeCode().equals(mcType)) {
                /* 判断查询类型 */
                CcbMcListInfoInObj ccbMcListInfoInObj = new CcbMcListInfoInObj();
                /* 机构编码 */
                ccbMcListInfoInObj.setInstId(globalInstId);
                /* 营销活动编号 */
                ccbMcListInfoInObj.setMcNo(globalMcNo);
                /* 机构编号 */
                if (!StringUtil.isNullorEmpty(globalQueryOrgId)) {
                    ccbMcListInfoInObj.setOrgId(globalQueryOrgId);
                }

                /* 校验查询类型权限 */
                if (QueryTypeEnum.BANK_QUERY_TYPE.getQueryTypeCode().equals(globalQueryType) ||
                        QueryTypeEnum.MCHNT_QYERY_TYPE.getQueryTypeCode().equals(globalQueryType) ||
                        QueryTypeEnum.CASHIER_QYERY_TYPE.getQueryTypeCode().equals(globalQueryType)) {
                    /* 根据角色权限查询数据 */
                    if (QueryRoleEnum.BANK_BASIC_QUERY_ROLE.getQueryRoleCode().equals(globalQueryRole) ||
                            QueryRoleEnum.BANK_PUBLISH_QYERY_ROLE.getQueryRoleCode().equals(globalQueryRole) ||
                            QueryRoleEnum.MCHNT_QYERY_ROLE.getQueryRoleCode().equals(globalQueryRole) ||
                            QueryRoleEnum.CASHIER_QYERY_ROLE.getQueryRoleCode().equals(globalQueryRole)) {

                        /* 查询营销活动商户信息 */
                        mcMchntInfoList = getAllMcMchntListInfo(pageInfo);
                        if (null != mcMchntInfoList && !mcMchntInfoList.isEmpty()) {
                            mcMchntInfoBeanList = mcMchntInfoList.stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
                        }
                        queryMcMerUserListInfoResponse.setMchntInfoList(mcMchntInfoBeanList);
                        //银行审批岗
                    } else if (QueryRoleEnum.BANK_AUDIT_QYERY_ROLE.getQueryRoleCode().equals(globalQueryRole)) {

                        /* 取临时表中所有数据 */
                        CcbMcListInfoInObj ccbMcListInfoInObj1 = new CcbMcListInfoInObj();
                        ccbMcListInfoInObj1.setInstId(globalInstId);
                        ccbMcListInfoInObj1.setMcNo(globalMcNo);
                        List<TMPlatBizTmp> tmPlatBizTmpList = getAllMcTmpInfo(ccbMcListInfoInObj1);
                        if (null != tmPlatBizTmpList && !tmPlatBizTmpList.isEmpty()) {
                            /* 查询营销活动商户信息 */
                            List<TMPlatBizTmp> tmPlatBizTmpMchntList = tmPlatBizTmpList.stream().filter(record -> TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameCode().equals(record.getOprTableEname())).collect(Collectors.toList());
                            mcMchntInfoBeanList = tmPlatBizTmpMchntList.stream().map(this::convertTmpMcMchntInfo).collect(Collectors.toList());
                            /* 临时表区分商户、商圈数据 */
                            rglog.info("机构<{}>的卡券类营销活动<{}>查询临时表商户列表size<{}>", globalInstId, globalMcNo, mcMchntInfoBeanList.size());
                            mcMchntInfoBeanList = mcMchntInfoBeanList.stream().filter(item -> globalMchntType.equals(item.getMchntType())).collect(Collectors.toList());
                            rglog.info("机构<{}>的卡券类营销活动<{}>商户列表筛选商户类型<{}>[0商户1商圈]，筛选后size<{}>", globalInstId, globalMcNo, globalMchntType, mcMchntInfoBeanList.size());
                        }
                        queryMcMerUserListInfoResponse.setMchntInfoList(mcMchntInfoBeanList);
                    } else {
                        /* 其他查询角色不支持 */
                        rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                        throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                    }
                } else {
                    /* 其他查询角色不支持 */
                    rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                    throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                }

            } else {
                rglog.error("营销活动类型上送错误!");
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            /** 用户列表信息查询 */
        } else if (TRANS_TYPE_USER.equals(transType)) {
            //权限校验
            List<Object> mcUserInfoList;

            //减免类
            if (McTypeEnum.REDUCTION_FIXED_AMOUNT.getMcTypeCode().equals(mcType) || McTypeEnum.REDUCTION_RANDOM_AMOUNT.getMcTypeCode().equals(mcType) ||
                    McTypeEnum.REDUCTION_FIXED_RATE.getMcTypeCode().equals(mcType) || McTypeEnum.REDUCTION_RANDOM_RATE.getMcTypeCode().equals(mcType)) {

                switch (QueryTypeEnum.getByValue(globalQueryType)) {
                    /* 银行人员查询 */
                    case BANK_QUERY_TYPE:
                        /* 查询营销活动用户信息*/
                        mcUserInfoList = getAllMcUserListInfo(pageInfo);
                        if (null != mcUserInfoList && !mcUserInfoList.isEmpty()) {
                            List<McUserInfoBean> mcUserInfoBeanList = mcUserInfoList.stream().map(this::convertMcUserInfo).collect(Collectors.toList());
                            queryMcMerUserListInfoResponse.setUserInfoList(mcUserInfoBeanList);
                        }
                        break;
                    /* 商户查询 */
                    case MCHNT_QYERY_TYPE:
                        /* 查询营销活动用户信息*/
                        mcUserInfoList = getAllMcUserListInfo(pageInfo);
                        if (null != mcUserInfoList && !mcUserInfoList.isEmpty()) {
                            List<McUserInfoBean> mcUserInfoBeanList = mcUserInfoList.stream().map(this::convertMcUserInfo).collect(Collectors.toList());
                            queryMcMerUserListInfoResponse.setUserInfoList(mcUserInfoBeanList);
                        }
                        break;
                    default:
                        /* 其他查询角色不支持 */
                        rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                        throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                }

                //卡券类
            } else if (McTypeEnum.COUPON_ALL.getMcTypeCode().equals(mcType) || McTypeEnum.COUPON_FREE.getMcTypeCode().equals(mcType) ||
                    McTypeEnum.COUPON_PAID.getMcTypeCode().equals(mcType)) {

                /* 判断查询类型 */
                CpMcListInfoInObj cpMcListInfoInObj = new CpMcListInfoInObj();
                /* 机构编码 */
                cpMcListInfoInObj.setInstId(globalInstId);
                /* 营销活动编号 */
                cpMcListInfoInObj.setMcNo(globalMcNo);

                /* 根据角色权限查询数据 */
                switch (QueryTypeEnum.getByValue(globalQueryType)) {
                    case BANK_QUERY_TYPE:
                        /* 银行人员,需要拼接营销活动机构信息表查询 */

                        /* 操作员所属机构编号 */
                        if (!StringUtil.isNullorEmpty(globalQueryOrgId)) {
                            cpMcListInfoInObj.setOrgId(globalQueryOrgId);
                        }

                        /* 银行人员查询营销活动详细信息 */
                        if (QueryRoleEnum.BANK_BASIC_QUERY_ROLE.getQueryRoleCode().equals(globalQueryRole) ||
                                QueryRoleEnum.BANK_PUBLISH_QYERY_ROLE.getQueryRoleCode().equals(globalQueryRole)) {

                            /* 查询营销活动用户信息 */
                            mcUserInfoList = getAllMcUserListInfo(pageInfo);
                            if (null != mcUserInfoList && !mcUserInfoList.isEmpty()) {
                                List<McUserInfoBean> mcUserInfoBeanList = mcUserInfoList.stream().map(this::convertMcUserInfo).collect(Collectors.toList());
                                queryMcMerUserListInfoResponse.setUserInfoList(mcUserInfoBeanList);
                            }
                        } else if (QueryRoleEnum.BANK_AUDIT_QYERY_ROLE.getQueryRoleCode().equals(globalQueryRole)) {
                            /* 银行审批岗流程 */
                            TMPlatBizTmp tmPlatBizTmp = selectCouponMcDetailInfoByBankAuditRole(cpMcListInfoInObj);
                            if (null == tmPlatBizTmp) {
                                rglog.error("机构<{}>的卡券类营销活动<{}>的基本信息查询失败!用户无权限查看数据或不存在该营销活动", globalInstId, globalMcNo);
                                throw new BizException(RespCodeEnum.GET_MONEY_OFF_MC_DETAIL_ERROR.getRespCode(), RespCodeEnum.GET_MONEY_OFF_MC_DETAIL_ERROR.getRespDesc());
                            }
                            /* 取临时表中所有数据 */
                            MoMcListInfoInObj moMcListInfoInObj = new MoMcListInfoInObj();
                            moMcListInfoInObj.setInstId(globalInstId);
                            moMcListInfoInObj.setMcNo(globalMcNo);

                            List<TMPlatBizTmp> tmPlatBizTmpList = getAllMcTmpInfo(moMcListInfoInObj);

                            /* 转换营销活动基本信息 */
                            CouponMcInfoBean couponMcInfoBean = convertTmpMcInfo(tmPlatBizTmp);
                            /* 查询营销活动用户信息 */
                            List<McUserInfoBean> mcUserInfoBeanList = new ArrayList<>();
                            if (CommonConstant.SPECIFIC_CLIENT_SUPPORT.equals(couponMcInfoBean.getClientRange()) && tmPlatBizTmpList != null) {
                                List<TMPlatBizTmp> tmPlatBizTmpUserList = tmPlatBizTmpList.stream().filter(record -> TableNameEnum.T_M_MC_USER_INFO.getTableNameCode().equals(record.getOprTableEname())).collect(Collectors.toList());
                                mcUserInfoBeanList = tmPlatBizTmpUserList.stream().map(this::convertTmpMcUserInfo).collect(Collectors.toList());
                            }
                            /* 客户范围-指定用户 */
                            if (CommonConstant.SPECIFIC_CLIENT_SUPPORT.equals(couponMcInfoBean.getClientRange())) {
                                queryMcMerUserListInfoResponse.setUserInfoList(mcUserInfoBeanList);
                            }
                        } else {
                            rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                            throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                        }
                        break;
                    case MCHNT_QYERY_TYPE:
                        /* 商户人员,需要拼接营销活动商户信息表查询 */
                        /* 根据商户编号查询商圈编号 */
                        String mchntNo = globalQueryId;
                        TBMchntBaseInfo tbMchntBaseInfo = null;
                        if (!StringUtil.isNullorEmpty(mchntNo)) {
                            /* 查询商户基本信息表 */
                            tbMchntBaseInfo = selectMompMchntBaseInfoByPrimaryKey(globalInstId, mchntNo);
                            if (null == tbMchntBaseInfo) {
                                rglog.error("查询法人机构<{}>商户<{}>基本信息失败!", globalInstId, mchntNo);
                                throw new BizException(RespCodeEnum.NO_TRANS_RECORD.getRespCode(), RespCodeEnum.NO_TRANS_RECORD.getRespDesc());
                            }
                        }
                        //查询用户信息
                        mcUserInfoList = getAllMcUserListInfo(pageInfo);
                        if (null != mcUserInfoList && !mcUserInfoList.isEmpty()) {
                            List<McUserInfoBean> mcUserInfoBeanList = mcUserInfoList.stream().map(this::convertMcUserInfo).collect(Collectors.toList());
                            queryMcMerUserListInfoResponse.setUserInfoList(mcUserInfoBeanList);
                        }
                        break;
                    default:
                        /* 其他查询角色不支持 */
                        rglog.error("当前<{}>角色的查询用户<{}>无权限操作数据!", globalQueryRole, globalQueryType);
                        throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_OPER_ERROR.getRespDesc());
                }
            } else {
                rglog.error("营销活动类型上送错误!");
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
        } else {
            rglog.error("交易类型上送错误!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }


        bizResponse.setRspSysId(ChannelEnum.MOMP.getChannelType());
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        queryMcMerUserListInfoResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        queryMcMerUserListInfoResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        queryMcMerUserListInfoResponse.setPageIndex(queryMcMerUserListRequest.getPageIndex());
        queryMcMerUserListInfoResponse.setPageSize(queryMcMerUserListRequest.getPageSize());
        queryMcMerUserListInfoResponse.setTotalPage(String.valueOf(pageInfo.getTotalPage()));
        queryMcMerUserListInfoResponse.setTotalRows(String.valueOf(pageInfo.getTotalRows()));

        bizResponse.setResult(queryMcMerUserListInfoResponse);

        return bizResponse;
    }


    /**
     * 请求报文体内容检查
     *
     * @param queryMcMerUserListRequest 减免类活动列表查询接口请求对象
     * @author Jinan Liu
     * @date 2020/6/20 09:55
     */
    private void messageValidation(QueryMcMerUserListRequest queryMcMerUserListRequest) {

        if (StringUtil.isNullorEmpty(queryMcMerUserListRequest.getHeader().getTransDate())) {
            rglog.error("交易日期必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        if (StringUtil.isNullorEmpty(queryMcMerUserListRequest.getHeader().getTransTime())) {
            rglog.error("交易时间必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        if (StringUtil.isNullorEmpty(queryMcMerUserListRequest.getHeader().getInstId())) {
            rglog.error("法人机构号必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalInstId = queryMcMerUserListRequest.getHeader().getInstId();
        }

        if (StringUtil.isNullorEmpty(queryMcMerUserListRequest.getHeader().getTraceNo())) {
            rglog.error("流水号必须上送!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        if (StringUtil.isNullorEmpty(queryMcMerUserListRequest.getQueryType())) {
            rglog.error("操作员类型为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalQueryType = queryMcMerUserListRequest.getQueryType();
        }

        if (StringUtil.isNullorEmpty(queryMcMerUserListRequest.getQueryId())) {
            rglog.error("操作员ID为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalQueryId = queryMcMerUserListRequest.getQueryId();
        }

        if (StringUtil.isNullorEmpty(queryMcMerUserListRequest.getQueryRole())) {
            rglog.error("操作员角色为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalQueryRole = queryMcMerUserListRequest.getQueryRole();
        }

        if (StringUtil.isNullorEmpty(queryMcMerUserListRequest.getQueryOrgId())) {
            rglog.error("操作员所属法人机构为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalQueryOrgId = queryMcMerUserListRequest.getQueryOrgId();
        }

        if (StringUtil.isNullorEmpty(queryMcMerUserListRequest.getMcNo())) {
            rglog.error("营销活动编号为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalMcNo = queryMcMerUserListRequest.getMcNo();
        }


        if (!StringUtil.isNullorEmpty(queryMcMerUserListRequest.getMchntNo())) {
            globalMchntNo = queryMcMerUserListRequest.getMchntNo();
        }

        if (StringUtil.isNullorEmpty(queryMcMerUserListRequest.getTransType())) {
            rglog.error("交易类型为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            transType = queryMcMerUserListRequest.getTransType();
        }

        if (TRANS_TYPE_MER.equals(transType)) {
            globalMchntType = CommonConstant.ZERO_COMMON_CONSTANT;
        } else if (TRANS_TYPE_AREAT.equals(transType)) {
            globalMchntType = CommonConstant.ONE_COMMON_CONSTANT;
        }

        if (StringUtil.isNullorEmpty(queryMcMerUserListRequest.getPageIndex())) {
            rglog.error("当前页数为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        if (StringUtil.isNullorEmpty(queryMcMerUserListRequest.getPageSize())) {
            rglog.error("页显示记录数为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        globalTimeStamp = new SimpleDateFormat(CommonConstant.TIMESTAMP_FORMAT).format(new Date());
    }

    private TMPlatBizTmp selectCouponMcDetailInfoByBankAuditRole(CpMcListInfoInObj cpMcListInfoInObj) throws Exception {
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        return platBizTmpMapper.selectCouponMcDetailInfoByBankAuditRole(cpMcListInfoInObj);
    }

    /**
     * 使用商户编号从内管商户基本信息表查询商户所属商圈编号
     *
     * @param globalInstId 法人机构号
     * @param mchntNo      商户编号
     * @return cc.rengu.igas.momp.common.entity.TBMchntBaseInfo 商户基本信息表T_B_MCHNT_BASE_INFO
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2021/3/25 13:06
     */
    private TBMchntBaseInfo selectMompMchntBaseInfoByPrimaryKey(String globalInstId, String mchntNo) throws Exception {
        MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();
        return mchntInfoMapper.selectMompMchntBaseInfoByPrimaryKey(globalInstId, mchntNo);
    }

    /**
     * 获取营销活动商户信息列表(正式表)
     *
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo> 营销活动商户信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 18:35
     */
    private List<Object> getAllMcMchntListInfo(PageInfo pageInfo) throws Exception {
        List<Object> tmMcMchntInfoList = new ArrayList<>();
        TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();
        tmMcMchntInfo.setInstId(globalInstId);
        tmMcMchntInfo.setMcNo(globalMcNo);
        tmMcMchntInfo.setMchntType(globalMchntType);
        if (!StringUtil.isNullorEmpty(globalMchntNo)) {
            tmMcMchntInfo.setMchntNo(globalMchntNo);
        }
        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        //不分页
        if (-1 == pageInfo.getPageIndex() || -1 == pageInfo.getPageSize()) {
            tmMcMchntInfoList = mcMchntInfoMapper.selectMcMchntInfoList(tmMcMchntInfo);
        } else {
            PageResult tmMcMchntInfoPageInfo = mcMchntInfoMapper.selectMcMchntInfoList(tmMcMchntInfo, pageInfo);
            if (null != tmMcMchntInfoPageInfo && null != tmMcMchntInfoPageInfo.getResult()) {
                tmMcMchntInfoList.addAll(tmMcMchntInfoPageInfo.getResult());
            }
        }
        return tmMcMchntInfoList;
    }


    /**
     * 卡券类营销活动基本信息数据库临时表实体类和接口实体类数据转换
     *
     * @param tmPlatBizTmp 业务数据临时表
     * @return cc.rengu.igas.momp.facade.bean.CouponMcInfoBean 卡券类活动基本信息对象
     * @author Jinan Liu
     * @date 2020/5/28 20:35
     */
    private CouponMcInfoBean convertTmpMcInfo(TMPlatBizTmp tmPlatBizTmp) {
        CouponMcInfoBean couponMcInfoBean = new CouponMcInfoBean();
        try {

            JsonTmpCpMcInfo jsonTmpCpMcInfo = JsonOperation.parseCpMcInfoTmpBizData1(tmPlatBizTmp, rglog);

            /* 营销活动编号 */
            couponMcInfoBean.setMcNo(jsonTmpCpMcInfo.getMcNo());
            /* 营销活动名称 */
            couponMcInfoBean.setMcName(jsonTmpCpMcInfo.getMcName());
            /* 营销活动类型 */
            couponMcInfoBean.setMcType(jsonTmpCpMcInfo.getMcType());
            /* 营销活动状态 */
            couponMcInfoBean.setMcStatus(jsonTmpCpMcInfo.getMcStatus());
            /* 活动起始日期 */
            couponMcInfoBean.setMcStartDate(jsonTmpCpMcInfo.getMcStartDate());
            /* 活动截止日期 */
            couponMcInfoBean.setMcEndDate(jsonTmpCpMcInfo.getMcEndDate());
            /* 活动结束日期 */
            couponMcInfoBean.setMcActualEndDate(jsonTmpCpMcInfo.getMcActualEndDate());
            /* 活动时间标志 */
            couponMcInfoBean.setMcTimeFlag(jsonTmpCpMcInfo.getMcTimeFlag());
            /* 出资方 */
            couponMcInfoBean.setSponsor(jsonTmpCpMcInfo.getSponsor());
            /* 参与次数限制 */
            couponMcInfoBean.setRestriction(jsonTmpCpMcInfo.getRestriction());
            /* 客户范围 */
            couponMcInfoBean.setClientRange(jsonTmpCpMcInfo.getClientRange());
            /* 商户范围 */
            couponMcInfoBean.setMerchantRange(jsonTmpCpMcInfo.getMerchantRange());
            /* 新增商户活动标志 */
            couponMcInfoBean.setNewMchntFlag(jsonTmpCpMcInfo.getNewMchntFlag());
            /* 限制金额下限 */
            couponMcInfoBean.setAmtLimitFloor(jsonTmpCpMcInfo.getAmtLimitFloor());
            /* 限制金额上限 */
            couponMcInfoBean.setAmtLimitCelling(jsonTmpCpMcInfo.getAmtLimitCelling());
            /* 预算充值方式 */
            couponMcInfoBean.setBudgetRechargeMethod(jsonTmpCpMcInfo.getBudgetRechargeMethod());
            /* 预算 */
            couponMcInfoBean.setBudget(jsonTmpCpMcInfo.getBudget());
            /* 银行出资预算 */
            couponMcInfoBean.setBankBudget(jsonTmpCpMcInfo.getBankBudget());
            /* 预期参与商户数量 */
            couponMcInfoBean.setExpectMchntQty(jsonTmpCpMcInfo.getExpectMchntQty());
            /* 银行出资比例 */
            couponMcInfoBean.setBankBudgetRatio(jsonTmpCpMcInfo.getBankBudgetRatio());
            /* 购买标志 */
            couponMcInfoBean.setPurchaseFlag(jsonTmpCpMcInfo.getPurchaseFlag());
            /* 卡券生效时间 */
            couponMcInfoBean.setAvailableDate(jsonTmpCpMcInfo.getAvailableDate());
            /* 卡券有效期标志 */
            couponMcInfoBean.setCouponDateFlag(jsonTmpCpMcInfo.getCouponDateFlag());
            /* 卡券有效起始日期 */
            couponMcInfoBean.setCouponStartDate(jsonTmpCpMcInfo.getCouponStartDate());
            /* 卡券有效结束日期 */
            couponMcInfoBean.setCouponEndDate(jsonTmpCpMcInfo.getCouponEndDate());
            /* 卡券相对周期 */
            couponMcInfoBean.setCouponPeriod(jsonTmpCpMcInfo.getCouponPeriod());
            /* 卡券库存 */
            couponMcInfoBean.setCouponInventory(jsonTmpCpMcInfo.getCouponInventory());
            /* 卡券库存 */
            couponMcInfoBean.setCouponRest(jsonTmpCpMcInfo.getCouponRest());
            /* 卡券已领取张数 */
            couponMcInfoBean.setCouponClaimed(jsonTmpCpMcInfo.getCouponClaimed());
            /* 卡券已核销张数 */
            couponMcInfoBean.setCouponRedeemed(jsonTmpCpMcInfo.getCouponRedeemed());
            /* 审批状态   */
            couponMcInfoBean.setAuditStatus(tmPlatBizTmp.getAuditStatus());
            /* 创建人 */
            couponMcInfoBean.setOprId(tmPlatBizTmp.getOprId());
            /* 创建时间 */
            couponMcInfoBean.setCreateTime(tmPlatBizTmp.getCreateTime());
            /* 最后修改人 */
            couponMcInfoBean.setLastOprId(tmPlatBizTmp.getLastOprId());
            /* 修改时间 */
            couponMcInfoBean.setUpdateTime(tmPlatBizTmp.getLastUpdateTime());
            /* 审批拒绝原因 */
            couponMcInfoBean.setAuditRefuseReason(tmPlatBizTmp.getAuditRefuseReason());
            /* 备用字段1 */
            couponMcInfoBean.setRemark1(tmPlatBizTmp.getRemark1());
            /* 备用字段2 */
            couponMcInfoBean.setRemark2(tmPlatBizTmp.getRemark2());
            /* 备用字段3 */
            couponMcInfoBean.setRemark2(tmPlatBizTmp.getRemark3());
            /* 备用字段4 */
            couponMcInfoBean.setRemark2(tmPlatBizTmp.getRemark4());
            /* 备用字段5 */
            couponMcInfoBean.setRemark2(tmPlatBizTmp.getRemark5());
        } catch (Exception e) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
            rglog.error("转换营销活动信息异常,异常信息:<{}>", byteArrayOutputStream.toString());
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return couponMcInfoBean;
    }


    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换
     *
     * @param object 营销活动商户信息表
     * @return cc.rengu.igas.momp.facade.bean.McMchntInfoBean 营销活动商户信息对象
     * @author Jinan Liu
     * @date 2020/4/1 10:33
     */
    private McMchntInfoBean convertMcMchntInfo(Object object) {
        McMchntInfoBean mcMchntInfoBean = new McMchntInfoBean();
        TMMcMchntInfo mcMchntInfo = (TMMcMchntInfo) object;
        try {
            /* 商户范围类型 */
            mcMchntInfoBean.setMchntType(mcMchntInfo.getMchntType());
            /* 商户范围号 */
            mcMchntInfoBean.setMchntNo(mcMchntInfo.getMchntNo());
            /* 商户范围名称 */
            mcMchntInfoBean.setMchntName(mcMchntInfo.getMchntName());
            /* 新增商户标志 */
            mcMchntInfoBean.setNewMchntFlag(mcMchntInfo.getNewMchntFlag());
            /* 退出标志 */
            mcMchntInfoBean.setExitFlag(mcMchntInfo.getExitFlag());
            /* 操作类型 */
            if ((CommonConstant.MCHNT_REFUSE_FLAG.equals(mcMchntInfo.getNewMchntFlag()) || CommonConstant.MCHNT_NEW_FLAG.equals(mcMchntInfo.getNewMchntFlag())) && CommonConstant.MC_EXIT_FLAG.equals(mcMchntInfo.getExitFlag())) {
                mcMchntInfoBean.setOprType(CommonConstant.BIZ_OPR_INSERT);
            } else {
                mcMchntInfoBean.setOprType(CommonConstant.EMPTY_STRING);
            }


        } catch (Exception e) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", byteArrayOutputStream.toString());
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcMchntInfoBean;
    }

    /**
     * 银行审批岗获取指定营销活动所有待审批数据
     *
     * @param moMcListInfoInObj 营销活动列表查询使用实体类入参
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMPlatBizTmp> 业务数据临时表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 19:55
     */
    private List<TMPlatBizTmp> getAllMcTmpInfo(MoMcListInfoInObj moMcListInfoInObj) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        return platBizTmpMapper.selectSingleMcAllDetailInfoByBankAuditRole(moMcListInfoInObj);
    }

    /**
     * 营销活动商户信息数据库临时表实体类和接口实体类数据转换
     *
     * @param tmPlatBizTmp 业务数据临时表
     * @return cc.rengu.igas.momp.facade.bean.McMchntInfoBean 营销活动商户信息对象
     * @author Jinan Liu
     * @date 2020/5/28 20:13
     */
    private McMchntInfoBean convertTmpMcMchntInfo(TMPlatBizTmp tmPlatBizTmp) {

        McMchntInfoBean mcMchntInfoBean = new McMchntInfoBean();
        try {

            JsonTmpMcMchntInfo jsonTmpMcMchntInfo = JsonOperation.parseTmpMcMchntInfoBizData1(tmPlatBizTmp, rglog);

            /* 商户范围类型 */
            mcMchntInfoBean.setMchntType(jsonTmpMcMchntInfo.getMchntType());
            /* 商户范围号 */
            mcMchntInfoBean.setMchntNo(jsonTmpMcMchntInfo.getMchntNo());
            /* 商户范围名称 */
            mcMchntInfoBean.setMchntName(jsonTmpMcMchntInfo.getMchntName());
            if (tmPlatBizTmp.getAuditStatus().equals(AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode()) || tmPlatBizTmp.getAuditStatus().equals(AuditStatusEnum.NEW_AUDIT_REJECT.getAuditStatusCode())
                    || tmPlatBizTmp.getAuditStatus().equals(AuditStatusEnum.PUBLISH_AUDIT_REJECT.getAuditStatusCode())) {
                /* 审批状态*/
                mcMchntInfoBean.setOprType(CommonConstant.BIZ_OPR_INSERT);
            }

        } catch (Exception e) {
            rglog.error("转换临时表营销活动机构信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcMchntInfoBean;
    }

    /**
     * 获取营销活动用户信息列表(正式表)
     *
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcUserInfo> 营销活动用户信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 18:38
     */
    private List<Object> getAllMcUserListInfo(PageInfo pageInfo) throws Exception {

        List<Object> tmMcMchntInfoList = new ArrayList<>();
        TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();
        tmMcMchntInfo.setInstId(globalInstId);
        tmMcMchntInfo.setMcNo(globalMcNo);

        McUserInfoMapper mcUserInfoMapper = new McUserInfoMapperImpl();
        PageResult mcUserInfoList = mcUserInfoMapper.selectMcUserInfoList(globalInstId, globalMcNo, pageInfo);

        if (null != mcUserInfoList && null != mcUserInfoList.getResult()) {
            tmMcMchntInfoList.addAll(mcUserInfoList.getResult());
        }
        return tmMcMchntInfoList;
    }

    /**
     * 营销活动用户规则信息数据库实体类和接口实体类数据转换
     *
     * @param object 营销活动用户信息表
     * @return cc.rengu.igas.momp.facade.bean.McUserInfoBean 营销活动用户信息对象
     * @author Jinan Liu
     * @date 2020/4/1 10:33
     */
    private McUserInfoBean convertMcUserInfo(Object object) {
        McUserInfoBean mcUserInfoBean = new McUserInfoBean();
        TMMcUserInfo mcUserInfo = (TMMcUserInfo) object;
        try {
            /* 账户类型 */
            mcUserInfoBean.setAcctType(mcUserInfo.getAcctType());
            /* 账户 */
            mcUserInfoBean.setAcctNo(mcUserInfo.getAcctNo());
            /* 会员ID */
            mcUserInfoBean.setMemberId(mcUserInfo.getMemberId());
            /* 每日限制优惠次数 */
            mcUserInfoBean.setDayRestriction(mcUserInfo.getDayRestriction());
            /* 每周限制优惠次数 */
            mcUserInfoBean.setWeekRestriction(mcUserInfo.getWeekRestriction());
            /* 每月限制优惠次数 */
            mcUserInfoBean.setMonthRestriction(mcUserInfo.getMonthRestriction());
            /* 每季度限制优惠次数 */
            mcUserInfoBean.setQuerterRestriction(mcUserInfo.getQuerterRestriction());
            /* 每年限制优惠次数 */
            mcUserInfoBean.setYearRestriction(mcUserInfo.getYearRestriction());
            /* 活动期间优惠次数限制 */
            mcUserInfoBean.setRestriction(mcUserInfo.getRestriction());
            /** 账户标志 */
            mcUserInfoBean.setAcctFlag(mcUserInfo.getAcctFlag());

        } catch (Exception e) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", byteArrayOutputStream.toString());
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcUserInfoBean;
    }

    /**
     * 营销活动用户信息数据库临时表实体类和接口实体类数据转换
     *
     * @param tmPlatBizTmp 业务数据临时表
     * @return cc.rengu.igas.momp.facade.bean.McUserInfoBean 营销活动用户信息对象
     * @author Jinan Liu
     * @date 2020/5/28 20:16
     */
    private McUserInfoBean convertTmpMcUserInfo(TMPlatBizTmp tmPlatBizTmp) {
        McUserInfoBean mcUserInfoBean = new McUserInfoBean();
        try {

            JsonTmpMcUserInfo jsonTmpMcUserInfo = JsonOperation.parseTmpMcUserInfoBizData1(tmPlatBizTmp, rglog);

            /* 账户类型 */
            mcUserInfoBean.setAcctType(jsonTmpMcUserInfo.getAcctType());
            /* 账户 */
            mcUserInfoBean.setAcctNo(jsonTmpMcUserInfo.getAcctNo());
            /* 会员ID */
            mcUserInfoBean.setMemberId(jsonTmpMcUserInfo.getMemberId());
            /* 每日限制优惠次数 */
            mcUserInfoBean.setDayRestriction(jsonTmpMcUserInfo.getDayRestriction());
            /* 每周限制优惠次数 */
            mcUserInfoBean.setWeekRestriction(jsonTmpMcUserInfo.getWeekRestriction());
            /* 每月限制优惠次数 */
            mcUserInfoBean.setMonthRestriction(jsonTmpMcUserInfo.getMonthRestriction());
            /* 每季度限制优惠次数 */
            mcUserInfoBean.setQuerterRestriction(jsonTmpMcUserInfo.getQuerterRestriction());
            /* 每年限制优惠次数 */
            mcUserInfoBean.setYearRestriction(jsonTmpMcUserInfo.getYearRestriction());
            /* 活动期间优惠次数限制 */
            mcUserInfoBean.setRestriction(jsonTmpMcUserInfo.getRestriction());

        } catch (Exception e) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", byteArrayOutputStream.toString());
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcUserInfoBean;
    }

    /**
     * 银行审批岗获取指定营销活动所有待审批数据
     *
     * @param ccbMcListInfoInObj 营销活动列表查询使用实体类入参
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMPlatBizTmp> 业务数据临时表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2021/3/24 19:55
     */
    private List<TMPlatBizTmp> getAllMcTmpInfo(CcbMcListInfoInObj ccbMcListInfoInObj) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        return platBizTmpMapper.selectCashierDetailInfoByBankAuditRole(ccbMcListInfoInObj);
    }

}
